<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta name="screen-orientation" content="portrait">
    <meta name="x5-orientation" content="portrait">
    <title>账单明细</title>
    <link rel="stylesheet" href="../../styles/h5/reset.min.css"/>
    <link rel="stylesheet" href="../../styles/h5/errortankuang.css"/>
    <!--以上为公共css样式-->
    <link rel="stylesheet" href="../../styles/h5/index.css"/>

    <script charset="utf-8" type="text/javascript" src="../../scripts/h5/jquery-1.9.1.min.js"></script>
    <script charset="utf-8" type="text/javascript" src="../../scripts/h5/jquery.modal.js"></script>
    <script charset="utf-8" type="text/javascript">
        countRem();
        function countRem(desW) {
            var desWh = desW || 750,
                    winW = document.documentElement.clientWidth;
            document.documentElement.style.fontSize = winW / desWh * 100 + "px";
        }
        $(window).resize(function () {
            countRem();
        });
    </script>
    <!--以上为公共js文件-->
</head>
<body>
<!--点击切换门店出现的列表-->
<div class="zz-shop-list">
    <span class="zz-shop-icon"></span>
    <select class="zz-shop" id="zz-shop">
        <!--<option value="111" storeId="11">阿里巴巴1</option>-->
        <!--<option value="222" storeId="22">阿里巴巴2</option>-->
    </select>
    <span class="zz-down-normal"></span>
</div>
<a class="zz-banner02-jj" id="zz-banner02-jj" href="javascript:;"></a>
<div class="zz-top"></div>

<div class="zz-list clear">
    <ul>
        <!--<li>-->
            <!--<a href="javascript:;">-->
                <!--<span class="zz-date">今天</span>-->
                <!--<span class="zz-right-arrow"></span>-->
                <!--<span class="zz-replace">笔</span>-->
                <!--<span class="zz-total-number">3</span>-->
                <!--<span class="zz-total-money zz-color">￥15.01</span>-->
                <!--<span class="zz-total">总计：</span>-->
            <!--</a>-->
        <!--</li>-->
    </ul>
</div>

<input type="button" class="footer zz-look-more" value="没有更多交易了"/>
<div class="footer-bottom"></div>
</body>

<script charset="utf-8" type="text/javascript" src="../../scripts/h5/utils.js"></script>
<script charset="utf-8" type="text/javascript">
    var $lookMore = $(".zz-look-more");
    var $listUl = $(".zz-list ul");
    var $shop = $("#zz-shop");
    var $banner02 = $("#zz-banner02-jj");
    var currentPage = 1;
    var pageSize = 7;
    var flag = true;
    var store = '';
    var order = '';
    var today = '';
    var yesterday = '';
    var storeId = '';
    var posReportId = '';

    function bindStore() {
        var str = '';
        for (var i = 0; i < store.length; i++) {
            var curData = store[i];
            if (curData.defultStore == 0) {
                str += '<option posReportId="'+curData.posReportId+'" storeId="' + curData.storeId + '" selected>' + curData.storeShortName + '</option>';
            } else {
                str += '<option posReportId="'+curData.posReportId+'" storeId="' + curData.storeId + '">' + curData.storeShortName + '</option>';
            }
        }
        $shop.html(str);
        storeId = $shop.find("option:selected").attr("storeId");
        posReportId = $shop.find("option:selected").attr("posReportId");
    }

    //初始化店铺
    $.ajax({
        url: utils.ajaxUrl()+"h5/store/receiver/getStoreByOpenid",
        async: false,
        type: 'get',
        success: function (res) {
        	var res = JSON.parse(res);
        	console.log(res);
            if (res && res.retCode == '0000') {
                store = res["storeList"];
                if (store && store.length > 0) {
                	bindStore();
                    bindHtml();
                }
            } else {
                utils.newModalPrompt(res.retMsg);
                $lookMore.attr("disabled", "true").val("没有更多交易了").css({"border":"none","background":"none"});
            }
        },
        error:function (){
        	$lookMore.attr("disabled", "true").val("没有更多交易了").css({"border":"none","background":"none"});
        	utils.newModalPrompt("网络异常");
    	}
    });


    function bindOrder() {
        storeId = $shop.find("option:selected").attr("storeId");
        posReportId = $shop.find("option:selected").attr("posReportId");
        var tradingStore = $shop.val();
        var strOrder = '';
        for (var j = 0; j < order.length; j++) {
            var curOrder = order[j];
            var date = curOrder["orderDate"].slice(0, 4) + "-" + curOrder["orderDate"].slice(4, 6) + "-" + curOrder["orderDate"].slice(6, 8);
            strOrder += '<li class="clear">';
            if (curOrder["dealNum"] == 0) {
                strOrder += '<a href="javascript:;" >';
            } else {
                strOrder += '<a href="../../html/h5/transactionList.html?storeId=' + storeId + '&orderDate=' + date + '&tradingStore=' + tradingStore + '&posReportId=' + posReportId + '">';
            }
            strOrder += '<span class="zz-date">' + date + '</span>';
            strOrder += '<span class="zz-right-arrow"></span>';
            strOrder += '<span class="zz-replace">笔</span>';
            strOrder += '<span class="zz-total-number">' + curOrder["dealNum"] + '</span>';
            strOrder += '<span class="zz-total-money zz-color">￥' + curOrder["dealAmt"] + '</span>';
            strOrder += '<span class="zz-total">总计：</span>';
            strOrder += '</a>';
            strOrder += '</li>';
        }
        if (flag) {
            $listUl.html(strOrder);
        } else {
            $listUl.append(strOrder);
        }

        var $listUlLi = $(".zz-list ul li");

        if ($listUlLi.find(".zz-date")[0] == undefined) {
            return;
        }

        var todayDate = $($listUlLi.find(".zz-date")[0]).html();
        todayDate = todayDate.slice(0, 4) + todayDate.slice(5, 7) + todayDate.slice(8, 10);
        if (today == todayDate) {
            $($listUlLi.find(".zz-date")[0]).html("今天")
        }

        if ($listUlLi.find(".zz-date")[1] == undefined) {
            return;
        }

        var yesterdayDate = $($listUlLi.find(".zz-date")[1]).html();
        yesterdayDate = yesterdayDate.slice(0, 4) + yesterdayDate.slice(5, 7) + yesterdayDate.slice(8, 10);
        if (yesterday == yesterdayDate) {
            $($listUlLi.find(".zz-date")[1]).html("昨天")
        }
    }
    //初始化账单
    function bindHtml() {
        $.ajax({
            url: utils.ajaxUrl()+"h5/billDetail/getBillDetailList",
            data: {
                storeId: storeId,
                currentPage: currentPage,
                pageSize: pageSize,
                posReportId: posReportId
            },
            //dataType: "json",
            async: false,
            type: 'get',
            success: function (re) {
            	var re = JSON.parse(re);
                console.log(re);
                if (re && re.retCode == '1') {
                    today = re.today;
                    yesterday = re.yesterday;
                    if (re.hasNextData != undefined && re.hasNextData) {
                        $lookMore.removeAttr("disabled").val("加载更多").css({"border":"1px solid #ddd","background":"#f4f4f4"});
                    } else {
                        $lookMore.attr("disabled", "true").val("没有更多交易了").css({"border":"none","background":"none"});
                    }
                    order = re["resultList"];

                    bindOrder();
                } else {
                    utils.newModalPrompt(re.retMsg);
                    $lookMore.attr("disabled", "true").val("没有更多交易了").css({"border":"none","background":"none"});
                }
            },
            error:function (){
            	$lookMore.attr("disabled", "true").val("没有更多交易了").css({"border":"none","background":"none"});
            	utils.newModalPrompt("网络异常");
        	}
        });
    }

	$.ajax({
        url: utils.ajaxUrl()+"h5/oAuchController/accountQuery",
        async: false,
        type: 'get',
        success: function (res) {
        	//var res = JSON.parse(res);
//        	console.log(res);
            if (res && res.retCode == '0000') {
            	if(res.accountType ==0){//未绑卡
                    $banner02.attr("href","../../html/h5/addBankCard.html?page=billMsg");
                }
                if(res.accountType ==1){//未开通
                    $banner02.attr("href","../../html/h5/fundNotOpen.html");
                }
                if(res.accountType ==2||res.accountType ==4){//2无权限，4已开通但持仓份额大于0
                    $banner02.hide();
                }
                if(res.accountType ==3){//已开通但持仓份额=0
                    $banner02.attr("href","../../html/h5/fundOpenAccount.html");
                }
            } else {
            	$banner02.hide();
                utils.newModalPrompt(res.retMsg);
            }
        },
        error:function (){
        	$banner02.hide();
            utils.newModalPrompt("网络异常");
        }
    });

</script>
<!-- <script charset="utf-8" type="text/javascript" src="../../scripts/h5/public.js"></script> -->
<!-- <script charset="utf-8" type="text/javascript" src="../../scripts/h5/index.js"></script> -->
<script charset="utf-8" type="text/javascript">
    $(function () {
        $shop.change(function () {
            storeId = $shop.find("option:selected").attr("storeId");
            posReportId = $shop.find("option:selected").attr("posReportId");
            currentPage = 1;
            flag = true;
            bindHtml();
        });
    });



    $lookMore.click(function () {
        currentPage++;
        storeId = $shop.find("option:selected").attr("storeId");
        posReportId = $shop.find("option:selected").attr("posReportId");
        console.log(storeId);
        flag = false;
        bindHtml();
    });

</script>
</html>